package net.realsee.framework.runner;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.realsee.common.config.AppConfig;
import net.realsee.service.system.ISysConfigService;
import net.realsee.service.system.ISysDictTypeService;
import net.realsee.service.system.ISysOssConfigService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 初始化 system 模块对应业务数据
 *
 * @author realsee
 */
@Slf4j
@RequiredArgsConstructor
@Component
public class SystemApplicationRunner implements ApplicationRunner {

    private final AppConfig appConfig;
    private final ISysConfigService configService;
    private final ISysDictTypeService dictTypeService;
    private final ISysOssConfigService ossConfigService;

    @Override
    public void run(ApplicationArguments args) {
        ossConfigService.init();
        if (!appConfig.isCacheLazy()) {
            configService.loadingConfigCache();
            dictTypeService.loadingDictCache();
        }
        this.activeHslCommunication();
    }

    /**
     * 激活PLC读写插件
     */
    private void activeHslCommunication() {
        if (HslCommunication.Authorization.SetAuthorizationCode("13ce3397-0cd1-4d8b-b1b1-3ccd41da087d")) {
            log.info("hslCommunication active success");
        } else {
            log.error("hslCommunication active failed");
        }
    }

}
